﻿// -----------------------------------------------------------------------
// <copyright file="CreditsScreen.cs" company="Diddly Squad">
// </copyright>
// -----------------------------------------------------------------------
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using System;

namespace DiddlySquat
{
	
	/// <summary>
	/// Creates Screen for credits
	/// </summary>
	public class CreditScreen : Screen
	{
		//Background texture for the screen
		readonly Texture2D pauseScreenBackground;

		private readonly SpriteFont font;
		private readonly SpriteFont menuFont;

		private int drawPositionY;

		private readonly GraphicsDeviceManager graphicsDeviceManager;

		/// <summary>
		/// Initializes a new instance of the <see cref="CreditScreen"/> class.
		/// </summary>
		/// <param name="theContent">The content.</param>
		/// <param name="theScreenEvent">The screen event.</param>
		/// <param name="graphics">The graphics.</param>
		public CreditScreen(ContentManager theContent, EventHandler theScreenEvent, GraphicsDeviceManager graphics)
			: base(theScreenEvent)
		{
			//Load resources for the screen
			pauseScreenBackground = theContent.Load<Texture2D>("GameScreen");
			font = theContent.Load<SpriteFont>("fonts/creditfont");
			menuFont = theContent.Load<SpriteFont>("fonts/menufont");

			drawPositionY = 100;
			this.graphicsDeviceManager = graphics;
		}

		/// <summary>
		/// Updates the sreen.
		/// </summary>
		/// <param name="theTime">The time.</param>
		public override void Update(GameTime theTime)
		{
			state = Keyboard.GetState();

			if (CheckKey(Keys.Enter) || CheckKey(Keys.Space))
			{
				ScreenEvent.Invoke(this, new EventArgs());
			}
			
			base.Update(theTime);
			oldState = Keyboard.GetState();
		}

		/// <summary>
		/// Draws to the batch.
		/// </summary>
		/// <param name="theBatch">The batch.</param>
		public override void Draw(SpriteBatch theBatch)
		{
			theBatch.Draw(pauseScreenBackground, Vector2.Zero, Color.White);

			drawPositionY = 100;

			const string text =
				"Credits: Diddly Squad:\n" + "Pekka Halonen\n" + "Erkki Heino\n"
				+ "Tuomas Valkeapää\n";

			//Find out screen correct place (x = screen center)
			theBatch.DrawString(font, text, new Vector2(graphicsDeviceManager.GraphicsDevice.Viewport.Width / 2 - (int)font.MeasureString(text).X, this.drawPositionY), Color.White);

			const string menuText = Constants.MenuOptionBack;

			drawPositionY += 5 * font.LineSpacing;

			theBatch.DrawString(menuFont, menuText, new Vector2(graphicsDeviceManager.GraphicsDevice.Viewport.Width / 2 - (int)menuFont.MeasureString(menuText).X, this.drawPositionY), Constants.SelectedMenuItemColor);

			base.Draw(theBatch);
		}

	}
}
